package com.ruoyi.home.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.contract.domain.Cproject;
import com.ruoyi.finance.model.Pfinance;
import com.ruoyi.home.service.IHomeService;
import com.ruoyi.project.model.BriefProject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/home")
public class HomeController extends BaseController {

    @Autowired
    private IHomeService homeService;

    @GetMapping("/all")
    public AjaxResult getStatistics(){
        Map<Integer, Map<String, Long>> statistics = homeService.getStatistics();
        return AjaxResult.success(statistics);
    }
    @GetMapping("/ht")
    public AjaxResult getHT(String type,Integer startYear,Integer endYear){
        switch (type){
            case "HT":
                return AjaxResult.success(homeService.getHTStatistics(startYear,endYear));
            case "SY":
                return AjaxResult.success(homeService.getSYStatistics(startYear,endYear));
            case "TZ":
                return AjaxResult.success(homeService.getTZStatistics(startYear,endYear));
            default:
                return AjaxResult.success();
        }
    }
    @GetMapping("/hk")
    public AjaxResult getHK(Integer startYear,Integer endYear){
        return AjaxResult.success(homeService.getHKStatistics(startYear,endYear));
    }
    @GetMapping("/jt")
    public AjaxResult getJT(Integer startYear,Integer endYear){
        return AjaxResult.success(homeService.getJTStatistics(startYear,endYear));
    }
    @GetMapping("/contractList")
    public TableDataInfo getContractList(Integer year,String type){
        List<Cproject> cprojects = homeService.getHtList(year,type);
        return getDataTable(cprojects);
    }
    @GetMapping("/cwList")
    public TableDataInfo getCwList(Integer year){
        List<Pfinance> cwList = homeService.getCwList(year);
        return getDataTable(cwList);
    }
    @GetMapping("/jtList")
    public TableDataInfo listBriefProject(Boolean finish,Integer year){
        List<BriefProject> briefProjects = homeService.getJtList(finish,year);
        return getDataTable(briefProjects);
    }
}
